package com.css.fxfzypg.modules.maps.service.impl;

import com.css.fxfzypg.modules.baseData.entity.FaultageEntity;
import com.css.fxfzypg.modules.maps.entity.GeomText;
import com.css.fxfzypg.modules.maps.service.SetEarthquakeMapService;
import com.css.fxfzypg.modules.preassesstaskmanage.entity.PreAssessTaskEntity;
import com.css.fxfzypg.modules.resultupload.repository.entity.ResultMainEntity;
import com.css.fxfzypg.org.entity.DivisionEntity;
import com.css.fxfzypg.util.PlatformObjectUtils;
import com.css.fxfzypg.zcpt.sys.service.SUserService;
import lombok.extern.slf4j.Slf4j;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Polygon;
import org.locationtech.jts.util.GeometricShapeFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;

/**
 * @Author zyt
 * @Date: 2022/10/18
 */
@Service
@Slf4j
public class SetEarthquakeMapServiceImpl implements SetEarthquakeMapService {
    @Resource
    JdbcTemplate jdbcTemplate;

    @Resource
    SUserService sUserService;

    /**
     * 数据源
     * 10.19.41.111
     */
    @Value("${spring.datasource.url}")
    private String url = "";
    @Value("${spring.datasource.username}")
    private String name = "";
    @Value("${spring.datasource.password}")
    private String pwd = "";

    /**
     * 获取数据库连接
     * SQL语句
     */
    private Connection getConnection() throws Exception {
        //Class.forName("com.mysql.cj.jdbc.Driver");
        Class.forName("org.postgresql.Driver");
        Connection conn = DriverManager.getConnection(url, name, pwd);
        return conn;
    }

    /*根据任务ID查询任务区域行政区划code列表*/
    @Override
    public List<String> getAllCodeListByTaskId(String id) {
        List<String> list = new ArrayList<String>();
        //查询条件
        if (!PlatformObjectUtils.isEmpty(id)) {
            StringBuilder sql = new StringBuilder("select task_district from ypg_preassess_task ");
            StringBuilder whereSql = new StringBuilder(" where del_flag='0'");
            whereSql.append(" and id='" + id + "'");
            sql.append(whereSql).toString();
            List<PreAssessTaskEntity> taskList = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(PreAssessTaskEntity.class));
            if (taskList != null && taskList.size() == 1) {
                String taskDistrict = taskList.get(0).getTaskDistrict();//任务地区
                if (!PlatformObjectUtils.isEmpty(taskDistrict)) {
                    if (taskDistrict.indexOf("、") != -1) {
                        String[] districtArr = taskDistrict.split("、");
                        for (int i = 0; i < districtArr.length; i++) {
                            String district = districtArr[i];
                            //根据1个任务地区查询行政区划code
                            String code = getCodeByTaskDistrict(district);
                            if (!PlatformObjectUtils.isEmpty(code)) {
                                list.add(code);
                            }
                        }
                    } else {
                        //根据1个任务地区查询行政区划code
                        String code = getCodeByTaskDistrict(taskDistrict);
                        if (!PlatformObjectUtils.isEmpty(code)) {
                            list.add(code);
                        }
                    }
                }
            }
        }
        return list;
    }

    //根据1个任务地区查询行政区划code
    @Override
    public String getCodeByTaskDistrict(String taskDistrict) {
        String code = "";
        if (!PlatformObjectUtils.isEmpty(taskDistrict)) {
            StringBuilder sql = new StringBuilder("SELECT * FROM org_division ");
            StringBuilder whereSql = new StringBuilder(" where is_valid='1'");
            if (taskDistrict.indexOf("-") != -1) {
                String[] districtArr = taskDistrict.split("-");
                if (districtArr.length == 2) {//市或直辖市的区
                    whereSql.append(" and division_name='" + districtArr[1] + "'");
                    whereSql.append(" and parent_id in (SELECT division_id FROM org_division ");
                    whereSql.append(" where is_valid='1' ");
                    whereSql.append(" and division_name='" + districtArr[0] + "')");

                } else if (districtArr.length == 3) {//区县
                    whereSql.append(" and division_name='" + districtArr[2] + "'");
                    whereSql.append(" and parent_id in (SELECT division_id FROM org_division ");
                    whereSql.append(" where is_valid='1' ");
                    whereSql.append(" and division_name='" + districtArr[1] + "'");
                    whereSql.append(" and parent_id in (SELECT division_id FROM org_division ");
                    whereSql.append(" where is_valid='1' ");
                    whereSql.append(" and division_name='" + districtArr[0] + "'))");
                }
            } else {
                //省
                whereSql.append(" and division_name='" + taskDistrict + "'");
            }
            sql.append(whereSql).toString();
            List<DivisionEntity> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(DivisionEntity.class));
            if (list != null && list.size() == 1) {
                String divisionCode = list.get(0).getDivisionCode();
                if (!PlatformObjectUtils.isEmpty(divisionCode)) {
                    code = divisionCode;
                }
            }
        }

        return code;
    }

    //获取任务区域内的相交的断层数据
    @Override
    public List<FaultageEntity> getIntersectionFaultByTaskId(String taskId) {
        String sql = "SELECT *,ST_AsText(x.geomIntersection) geomText FROM (" +
                "SELECT *,st_intersection(s.geom, (SELECT m.geom FROM ypg_preassess_task m " +
                "WHERE m.id = '" + taskId + "')) geomIntersection FROM data_faultage s " +
                "WHERE s.fau_id in (SELECT a.fau_id FROM data_faultage a " +
                "WHERE fau_isdelete='0' and ST_Intersects(a.geom,(SELECT b.geom FROM ypg_preassess_task b " +
                "WHERE b.id = '" + taskId + "')))) x";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(FaultageEntity.class));
    }

    //判断经纬度是否在任务区域内部（不包括边线）
    @Override
    public boolean isTaskRegionContainsLonLat(String taskId, String lonlat) {
        boolean bool = false;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(lonlat)) {
                conn = getConnection();
                String sql = "SELECT ST_Within(st_geometryfromtext('POINT(" + lonlat + ")',4490)," +
                        "(select a.geom FROM ypg_preassess_task a " +
                        "WHERE a.id = '" + taskId + "')) result";
                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String result = rs.getString("result");
                    if (result.equals("t")) {//经纬度在面内部（不包括边线）
                        bool = true;
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return bool;
    }

    //判断经纬度是否在任务区域边线上（不包括区域内部）
    @Override
    public boolean isTaskRegionTouchesLonLat(String taskId, String lonlat) {
        boolean bool = false;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(lonlat)) {
                conn = getConnection();
                String sql = "SELECT ST_Touches(st_geometryfromtext('POINT(" + lonlat + ")',4490)," +
                        "(select a.geom FROM ypg_preassess_task a " +
                        "WHERE a.id = '" + taskId + "')) result";
                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String result = rs.getString("result");
                    if (result.equals("t")) {//经纬度在面内部（不包括边线）
                        bool = true;
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return bool;
    }

    //根据全部经纬度字符串获取任务区域内的经纬度字符串（多点相交）
    @Override
    public String getLonLatsStringByTaskId(String taskId, String lonlatsString) {
        String result = "";
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(lonlatsString)) {
                conn = getConnection();
                String sql = "SELECT ST_AsText(st_intersection(" +
                        "(select a.geom FROM ypg_preassess_task a " +
                        "WHERE a.id = '" + taskId + "'), " +
                        "st_geometryfromtext('MULTIPOINT(" + lonlatsString + ")',4490)" +
                        ")) result";
                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    result = rs.getString("result");
                    if (!PlatformObjectUtils.isEmpty(result)) {
                        if (result.indexOf("POINT") != -1) {
                            result = result.split("POINT\\(")[1].split("\\)")[0];
                        }
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return result;
    }

    //根据经纬度字符串查询全部经纬度及行政区划省市区县信息字符串（经度,纬度,省,市,区县;）
    @Override
    public String queryAllLonLatProvinceCityCountyNameStringByLonLatsString(String lonlatsString) {
        String result = "";
        if (!PlatformObjectUtils.isEmpty(lonlatsString)) {
            String[] lonlatStrArr = lonlatsString.split(";");
            if (lonlatStrArr != null && lonlatStrArr.length > 0) {
                for (int i = 0; i < lonlatStrArr.length; i++) {
                    String[] lonlatArr = lonlatStrArr[i].split(",");
                    String lon = lonlatArr[0];
                    String lat = lonlatArr[1];
                    //根据经纬度查询行政区划省市区县信息字符串（省,市,区县）
                    String provinceCityCountyNameString = queryProvinceCityCountyNameStringByLonLat(lon, lat);
                    if (i > 0) {
                        result += ";";
                    }
                    //经度,纬度,省,市,区县;
                    result += lonlatStrArr[i] + "," + provinceCityCountyNameString;
                }
            }
        }

        return result;
    }

    //根据经纬度查询行政区划省市区县信息字符串（省,市,区县）
    @Override
    public String queryProvinceCityCountyNameStringByLonLat(String lon, String lat) {
        String result = "";
        if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
            //省
            List<String> provinceInfoList = queryProvinceByLonLat(lon, lat);
            if (provinceInfoList.size() > 0) {
                String provinceCode = provinceInfoList.get(0);
                String provinceName = provinceInfoList.get(1);
                result += provinceName;
                //市
                List<String> cityInfoList = queryCityByLonLat(lon, lat, provinceCode);
                if (cityInfoList.size() > 0) {
                    String cityCode = cityInfoList.get(0);
                    String cityName = cityInfoList.get(1);
                    result += "," + cityName;
                    //区县
                    List<String> countyInfoList = queryCountyByLonLat(lon, lat, cityCode);
                    if (countyInfoList.size() > 0) {
                        //String countyCode = countyInfoList.get(0);
                        String countyName = countyInfoList.get(1);
                        result += "," + countyName;
                        //乡镇、街道
                        List<String> townNameList = queryTownNameByLonLat(lon, lat, provinceName, cityName, countyName);
                        if (townNameList.size() > 0) {
                            String townName = townNameList.get(0);
                            result += "," + townName;
                        }
                    }
                }
            }
        }

        return result;
    }

    //根据经纬度查询行政区划--省份code和名称
    @Override
    public List<String> queryProvinceByLonLat(String lon, String lat) {
        List<String> resultList = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                //查询行政区划--省
                String sql = "SELECT code,name FROM district_boundary_province t " +
                        "WHERE ST_Within(ST_GeometryFromText('POINT (" + lon + " " + lat + ")',4490),t.geom) ";
                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String code = rs.getString("code");//行政区划编码
                    resultList.add(code);
                    String name = rs.getString("name");//行政区划名称
                    resultList.add(name);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据经纬度查询行政区划--市code和名称
    @Override
    public List<String> queryCityByLonLat(String lon, String lat, String provinceCode) {
        List<String> resultList = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                //查询行政区划--市
                String sql = "SELECT code,name FROM district_boundary_city t WHERE ";
                if (!PlatformObjectUtils.isEmpty(provinceCode)) {//省code
                    String tempCode = provinceCode.substring(0, 2);
                    sql += "t.code like '" + tempCode + "%' and ";
                }
                sql += "ST_Within(ST_GeometryFromText('POINT (" + lon + " " + lat + ")',4490),t.geom) ";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String code = rs.getString("code");//行政区划编码
                    resultList.add(code);
                    String name = rs.getString("name");//行政区划名称
                    resultList.add(name);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据经纬度查询行政区划--区县code和名称
    @Override
    public List<String> queryCountyByLonLat(String lon, String lat, String cityCode) {
        List<String> resultList = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                //查询行政区划--区县
                String sql = "SELECT code,name FROM district_boundary_county t WHERE ";
                if (!PlatformObjectUtils.isEmpty(cityCode)) {//市code
                    String tempCode = cityCode.substring(0, 4);
                    sql += "t.code like '" + tempCode + "%' and ";
                }
                sql += "ST_Within(ST_GeometryFromText('POINT (" + lon + " " + lat + ")',4490),t.geom) ";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String code = rs.getString("code");//行政区划编码
                    resultList.add(code);
                    String name = rs.getString("name");//行政区划名称
                    resultList.add(name);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据经纬度查询行政区划--乡镇名称
    @Override
    public List<String> queryTownNameByLonLat(String lon, String lat, String province, String city, String county) {
        List<String> resultList = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                //查询行政区划--区县
                String sql = "SELECT street FROM data_area t WHERE ";
                if (!PlatformObjectUtils.isEmpty(province)) {//省
                    sql += "t.province like '" + province + "%' and ";
                }
                if (!PlatformObjectUtils.isEmpty(city)) {//市
                    sql += "t.city like '" + city + "%' and ";
                }
                if (!PlatformObjectUtils.isEmpty(county)) {//区县
                    sql += "t.county like '" + county + "%' and ";
                }
                sql += "ST_Within(ST_GeometryFromText('POINT (" + lon + " " + lat + ")',4490),t.geom) ";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String street = rs.getString("street");//乡镇、街道
                    resultList.add(street);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //获取任务范围最小矩形的经纬度值数组
    @Override
    public List<Double> getTaskRegionExtent(String taskId) {
        List<Double> list = new ArrayList<Double>();
        if (!PlatformObjectUtils.isEmpty(taskId)) {
            String sql = "select ST_extent(geom) as geom from ypg_preassess_task " +
                    "where del_flag='0' and id='" + taskId + "' ";
            GeomText geomText = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(GeomText.class));
            if (!PlatformObjectUtils.isEmpty(geomText.getGeom())) {
                //获取区域范围最小矩形
                String extent = geomText.getGeom();
                if (extent.indexOf("BOX(") != -1) {
                    extent = geomText.getGeom().split("BOX\\(")[1].split("\\)")[0];
                    String[] tempArr = extent.split(",");
                    if (tempArr.length == 2) {
                        String[] minTempArr = tempArr[0].split(" ");
                        String[] maxTempArr = tempArr[1].split(" ");
                        if (minTempArr.length == 2 && maxTempArr.length == 2) {
                            double minLongitude = Double.parseDouble(minTempArr[0]);//经度最小值
                            double minLatitude = Double.parseDouble(minTempArr[1]);//纬度最小值
                            double maxLongitude = Double.parseDouble(maxTempArr[0]);//经度最大值
                            double maxLatitude = Double.parseDouble(maxTempArr[1]);//纬度最大值
                            list.add(minLongitude);//经度最小值
                            list.add(minLatitude);//纬度最小值
                            list.add(maxLongitude);//经度最大值
                            list.add(maxLatitude);//纬度最大值
                        }
                    }
                }
            }
        }

        return list;
    }

    //获取任务范围的正方形公里格网网格线和震中位置经纬度列表（以右上角为初始点）
    @Override
    public List<List<Double>> getSquareGridCenterLonLatList(String taskId, String kilometer) {
        List<List<Double>> list = new ArrayList<List<Double>>();
        List<Double> extent = getTaskRegionExtent(taskId);//获取任务范围最小矩形的经纬度值数组
        if (extent.size() == 4 && !PlatformObjectUtils.isEmpty(kilometer)) {
            double minLongitude = extent.get(0);//经度最小值
            double minLatitude = extent.get(1);//纬度最小值
            double maxLongitude = extent.get(2);//经度最大值
            double maxLatitude = extent.get(3);//纬度最大值
            //以右上角为初始点
            double currentLon = maxLongitude;//经度最大值
            double currentLat = maxLatitude;//纬度最大值
            //距离（米）
            double meter = Double.parseDouble(kilometer) * 1000;
            //将距离转换为度数
            double latIntervalDegree = parseYLengthToDegree(meter);//获取纬度间隔kilometer公里的度数
            //获取纬度为currentLat时，经度间隔kilometer公里的度数
            double lonIntervalDegree = parseXLengthToDegree(currentLat, meter);
            //经度x轴的网格个数
            double lonCount = Math.floor((maxLongitude - minLongitude) / lonIntervalDegree);
            //纬度y轴的网格个数
            double latCount = Math.floor((maxLatitude - minLatitude) / latIntervalDegree);
            //经度x轴的网格余数
            double remLon = (maxLongitude - minLongitude) - lonCount * lonIntervalDegree;
            //纬度y轴的网格余数
            double remLat = (maxLatitude - minLatitude) - latCount * latIntervalDegree;
            //所有网格线的经度、纬度列表
            List<Double> lonList = new ArrayList<Double>();
            List<Double> latList = new ArrayList<Double>();
            for (int i = 0; i <= latCount; i++) {
                currentLat = maxLatitude - latIntervalDegree * i;//当前计算的纬度
                latList.add(currentLat);
            }
            if (remLat > 0) {//纬度y轴的网格余数
                latList.add(minLatitude);//纬度最小值
            }
            for (int j = 0; j <= lonCount; j++) {
                currentLon = maxLongitude - lonIntervalDegree * j;//当前计算的经度
                lonList.add(currentLon);
            }
            if (remLon > 0) {//经度x轴的网格余数
                lonList.add(minLongitude);//经度最小值
            }
            //震中位置经度、纬度列表
            List<Double> centerLonList = new ArrayList<Double>();
            List<Double> centerLatList = new ArrayList<Double>();
            if (lonList.size() >= 2) {
                for (int i = 0; i < lonList.size(); i++) {
                    if (i < lonCount) {
                        double centerLon = lonList.get(i) - lonIntervalDegree / 2;
                        centerLonList.add(centerLon);
                    } else {
                        double centerLon = lonList.get(i) - lonIntervalDegree / 2;
                        if (centerLon >= minLongitude) {
                            centerLonList.add(centerLon);
                        }
                    }
                }
                for (int i = 0; i < latList.size(); i++) {
                    if (i < latCount) {
                        double centerLat = latList.get(i) - latIntervalDegree / 2;
                        centerLatList.add(centerLat);
                    } else {
                        double centerLat = latList.get(i) - latIntervalDegree / 2;
                        if (centerLat >= minLatitude) {
                            centerLatList.add(centerLat);
                        }
                    }
                }
            }
            //返回结果
            list.add(extent);//任务范围最小矩形的经纬度值数组
            list.add(lonList);//所有网格线的经度列表
            list.add(latList);//所有网格线的纬度列表
            list.add(centerLonList);//震中位置经度列表
            list.add(centerLatList);//震中位置纬度列表

            /*//震中位置空间数据数组
            List<String> centerGeomStrList = new ArrayList<String>();
            if(centerLonList.size()>0 && centerLatList.size()>0) {
                for (int i = 0; i < centerLonList.size(); i++) {
                    double lon = centerLonList.get(i);
                    for (int j = 0; j < centerLatList.size(); j++) {
                        double lat = centerLatList.get(j);
                        String geomStr = "POINT (" + lon + " " + lat + ")";
                        centerGeomStrList.add(geomStr);
                    }
                }
            }
            //格网空间数据数组
            List<String> gridGeomStrList = new ArrayList<String>();
            if(lonList.size()>0 && latList.size()>0) {
                for (int i = 0; i < (lonList.size()-1); i++) {
                    double lon = lonList.get(i);
                    double lon1 = lonList.get(i+1);
                    for (int j = 0; j < (latList.size()-1); j++) {
                        double lat = latList.get(j);
                        double lat1 = latList.get(j+1);
                        String geomStr = "POLYGON ((" + lon + " " + lat + "," + lon1 + " " + lat + "," + lon1 + " " + lat1 + "," + lon + " " + lat1 + "," + lon + " " + lat + "))";
                        gridGeomStrList.add(geomStr);
                    }
                }
            }*/

        }

        return list;
    }

    //创建地震影响场
    @Override
    public String createInfluenceEllipse(String lon, String lat, String long_x, String short_y, String angle, String min_long_x, String min_short_y) {
        String result = "";
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)
                    && !PlatformObjectUtils.isEmpty(long_x) && !PlatformObjectUtils.isEmpty(short_y)) {
                double x = Double.parseDouble(lon);//经度
                double y = Double.parseDouble(lat);//纬度
                double macroaxis = Double.parseDouble(long_x) * 1000;//长轴（米）
                double brachyaxis = Double.parseDouble(short_y) * 1000;//短轴（米）
                double direction = 0;//旋转角度
                if (!PlatformObjectUtils.isEmpty(angle)) {
                    direction = Double.parseDouble(angle);//旋转角度
                }
                //创建椭圆
                Polygon ellipse = createEllipse(x, y, macroaxis, brachyaxis, direction);
                if (!PlatformObjectUtils.isEmpty(min_long_x) && !PlatformObjectUtils.isEmpty(min_short_y)) {//内圈椭圆
                    double min_macroaxis = Double.parseDouble(min_long_x) * 1000;//内圈长轴（米）
                    double min_brachyaxis = Double.parseDouble(min_short_y) * 1000;//内圈短轴（米）
                    //创建内圈椭圆
                    Polygon innerEllipse = createEllipse(x, y, min_macroaxis, min_brachyaxis, direction);
                    result = ellipse.toString() + ";" + innerEllipse.toString();
                    result = result.replace("));POLYGON ((", "), (");
                } else {//无内圈椭圆
                    //返回结果
                    result = ellipse.toString();
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }

        return result;
    }

    //获取地震影响场范围最小矩形的经纬度值数组
    public List<String> getInfluenceEllipseEnvelope(Polygon ellipse) {
        List<String> list = new ArrayList<String>();
        if (ellipse != null) {
            //获取区域范围最小矩形
            String envelope = ellipse.getEnvelope().toString();
            //解析空间数据经纬度
            String maxLongitude = "";//经度最大值
            String minLongitude = "";//经度最小值
            String maxLatitude = "";//纬度最大值
            String minLatitude = "";//纬度最小值
            //获取区域范围最小矩形的经纬度值
            if (envelope.indexOf("POLYGON ((") != -1) {
                String tempStr = envelope.split("POLYGON \\(\\(")[1].split("\\)\\)")[0];
                String[] tempArr = tempStr.split(", ");
                if (tempArr.length > 0) {
                    for (int m = 0; m < tempArr.length; m++) {
                        String[] tempLonLat = tempArr[m].split(" ");
                        String tempLon = tempLonLat[0];
                        String tempLat = tempLonLat[1];
                        if (maxLongitude == "") {
                            maxLongitude = tempLon;
                        } else if (Double.parseDouble(maxLongitude) < Double.parseDouble(tempLon)) {
                            maxLongitude = tempLon;
                        }
                        if (minLongitude == "") {
                            minLongitude = tempLon;
                        } else if (Double.parseDouble(minLongitude) > Double.parseDouble(tempLon)) {
                            minLongitude = tempLon;
                        }
                        if (maxLatitude == "") {
                            maxLatitude = tempLat;
                        } else if (Double.parseDouble(maxLatitude) < Double.parseDouble(tempLat)) {
                            maxLatitude = tempLon;
                        }
                        if (minLatitude == "") {
                            minLatitude = tempLat;
                        } else if (Double.parseDouble(minLatitude) > Double.parseDouble(tempLat)) {
                            minLatitude = tempLat;
                        }
                    }
                }
            }
            list.add(maxLongitude);//经度最大值
            list.add(minLongitude);//经度最小值
            list.add(maxLatitude);//纬度最大值
            list.add(minLatitude);//纬度最小值
        }

        return list;
    }

    //获取任务区域的空间数据
    @Override
    public String getGeomByTaskRegion(String taskRegion) {
        String geom = null;
        if (!PlatformObjectUtils.isEmpty(taskRegion)) {
            if (taskRegion.indexOf("MULTIPOLYGON") != -1) {//行政区划选择区域
//                geom = taskRegion.replace(")));MULTIPOLYGON (((", ")), ((");
                geom = getTaskRegionGeomUnion(taskRegion);//获取任务区域合并后的空间数据
                if(geom.startsWith("POLYGON")){
                    geom = geom.replace("POLYGON((", "MULTIPOLYGON(((") + ")";
                }
            } else {//地图圈选区域
                taskRegion = taskRegion.replace(",", " ");
                taskRegion = taskRegion.replace(";", ",");
                geom = "MULTIPOLYGON (((" + taskRegion + ")))";
            }
        }

        return geom;
    }

    //获取任务区域合并后的空间数据
    public String getTaskRegionGeomUnion(String taskRegion) {
        String sql = "select st_astext(st_union(st_geomfromtext(a.geomtext,4490))) from " +
                "(SELECT regexp_split_to_table (?, ';') as geomtext) a";
        return jdbcTemplate.queryForObject(sql, String.class, taskRegion);
    }

    @Override
    public List<ResultMainEntity> getResultTotalByTaskId(String taskId) {
        if (!PlatformObjectUtils.isEmpty(taskId)) {
            String sql = "select sort,longitude,latitude from ypg_result_total " +
                    "where del_flag='0' and task_id='" + taskId + "' " +
                    "group by sort,longitude,latitude " +
                    "order by cast(sort as int) asc";
            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ResultMainEntity.class));
        } else {
            return null;
        }
    }

    @Override
    public List<ResultMainEntity> getResultTotalDetailByTaskIdNum(String taskId, String num) {
        if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(num)) {
            String sql = "select * from ypg_result_total_details where del_flag='0' " +
                    "and task_id='" + taskId + "' and sort='" + num + "' " +
                    "order by cast(sort as int) asc,magnitude asc,cast(angle as int) asc;";
            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ResultMainEntity.class));
        } else {
            return null;
        }
    }

    //根据taskId，查询全部设定地震的震级列表
    @Override
    public List<String> queryInfluencefliedLevelListByTaskId(String taskId) {
        List<String> resultList = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId)) {
                conn = getConnection();
                StringBuilder sql = new StringBuilder("select magnitude from ypg_result_total_details ");
                String whereSql = "where task_id='" + taskId + "' ";
                sql.append(whereSql);
                String groupSql = "group by magnitude ";
                sql.append(groupSql);
                String orderSql = "order by magnitude ";
                sql.append(orderSql);
                ps = conn.prepareStatement(sql.toString());
                rs = ps.executeQuery();
                while (rs.next()) {
                    String dzIntensity = rs.getString("magnitude");
                    resultList.add(dzIntensity);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据taskId、序号，查询震级列表
    @Override
    public List<String> queryInfluencefliedLevelList(String taskId, String num) {
        List<String> resultList = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(num)) {
                conn = getConnection();
                StringBuilder sql = new StringBuilder("select magnitude from ypg_result_total_details ");
                String whereSql = "where task_id='" + taskId + "' and sort='" + num + "' ";
                sql.append(whereSql);
                String groupSql = "group by magnitude ";
                sql.append(groupSql);
                String orderSql = "order by magnitude ";
                sql.append(orderSql);
                ps = conn.prepareStatement(sql.toString());
                rs = ps.executeQuery();
                while (rs.next()) {
                    String dzIntensity = rs.getString("magnitude");
                    resultList.add(dzIntensity);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据taskId、序号，查询角度列表
    @Override
    public List<String> queryInfluencefliedAngleList(String taskId, String num) {
        List<String> resultList = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(num)) {
                conn = getConnection();
                StringBuilder sql = new StringBuilder("select angle from ypg_result_total_details ");
                String whereSql = "where task_id='" + taskId + "' and sort='" + num + "' and sort='" + num + "' ";
                sql.append(whereSql);
                String groupSql = "group by angle ";
                sql.append(groupSql);
                String orderSql = "order by cast(angle as int) asc ";
                sql.append(orderSql);
                ps = conn.prepareStatement(sql.toString());
                rs = ps.executeQuery();
                while (rs.next()) {
                    String dzIntensity = rs.getString("angle");
                    resultList.add(dzIntensity);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据taskId、震级、查询类型、序号总个数，按序号从小到大排序查询全部评估结果（未选择角度：最小值,最大值）
    @Override
    public List<List<String>> queryAllEvaluateResultTotalDetails(String taskId, String level, String type, String lengthStr) {
        List<List<String>> resultList = new ArrayList<List<String>>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(level)
                    && !PlatformObjectUtils.isEmpty(lengthStr) && !PlatformObjectUtils.isEmpty(type)) {
                conn = getConnection();
                int length = Integer.parseInt(lengthStr);
                for (int i = 0; i < length; i++) {
                    resultList.add(null);
                }
                String searchType = "";//查询字段值
                String searchType2 = "";//查询字段值2
                String searchType3 = "";//查询字段值3
                String searchType4 = "";//查询字段值4
                if (type.equals("人员伤亡")) {
                    searchType = "death_toll";//死亡人数（人）
                    searchType2 = "injured_num";//受伤人数（人）--查询字段值2
                } else if (type.equals("经济损失")) {
                    searchType = "disaster_loss";
                } else if (type.equals("需紧急安置人数")) {
                    searchType = "resettled_num";
                } else if (type.equals("需救援队伍")) {
                    searchType = "rescue_force";//需救援队伍（人）
                    searchType2 = "rescue_force_zy";//专业救援力量（人）--查询字段值2
                    searchType3 = "rescue_force_mj";//民间救援力量（人）--查询字段值3
                    searchType4 = "rescue_force_qt";//社会其他救援力量（人）--查询字段值4
                } else if (type.equals("需医务人员")) {
                    searchType = "medical_matters";//需医务人员（人）
                    searchType2 = "medical_num";//医生（人）--查询字段值2
                    searchType3 = "nurse_num";//护士（人）--查询字段值3
                    searchType4 = "psychologist";//心理医生（人）--查询字段值4
                } else if (type.equals("需帐篷数")) {//需救援物资
                    searchType = "tent_num";
                } else if (type.equals("需担架")) {//需救援物资
                    searchType = "stretcher_num";
                } else if (type.equals("需棉被")) {//需救援物资
                    searchType = "quilts_num";
                } else if (type.equals("需食品")) {//需救援物资
                    searchType = "foods_num";
                } else if (type.equals("需饮水")) {//需救援物资
                    searchType = "water_num";
                } else if (type.equals("需临时厕所")) {//需救援物资
                    searchType = "bathroom_num";
                } else if (type.equals("需临时浴室")) {//需救援物资
                    searchType = "showers_num";
                } else if (type.equals("需医疗物资")) {
                    searchType = "sickroom_num";//需病房（平方米）
                    searchType2 = "sickbed_num";//需病床（张）--查询字段值2
                    searchType3 = "plasma_num";//需血浆（升）--查询字段值3
                }

                //查询
                if (!PlatformObjectUtils.isEmpty(searchType)) {
                    String tempSql = "select sort,min(cast(" + searchType + " as float)),max(cast(" + searchType + " as float))";
                    if (!PlatformObjectUtils.isEmpty(searchType2)) {//查询字段值2
                        tempSql += ",min(cast(" + searchType2 + " as float)) min2,max(cast(" + searchType2 + " as float)) max2";
                    }
                    if (!PlatformObjectUtils.isEmpty(searchType3)) {//查询字段值3
                        tempSql += ",min(cast(" + searchType3 + " as float)) min3,max(cast(" + searchType3 + " as float)) max3";
                    }
                    if (!PlatformObjectUtils.isEmpty(searchType4)) {//查询字段值4
                        tempSql += ",min(cast(" + searchType4 + " as float)) min4,max(cast(" + searchType4 + " as float)) max4";
                    }
                    tempSql += " from ypg_result_total_details ";
                    StringBuilder sql = new StringBuilder(tempSql);
                    String whereSql = "where del_flag='0' and magnitude='" + level + "' and task_id='" + taskId + "' ";
                    sql.append(whereSql);
                    String groupSql = "group by sort ";
                    sql.append(groupSql);
                    String orderSql = "order by cast(sort as int) ";
                    sql.append(orderSql);
                    ps = conn.prepareStatement(sql.toString());
                    rs = ps.executeQuery();
                    while (rs.next()) {
                        String sort = rs.getString("sort");
                        int index = Integer.parseInt(sort) - 1;
                        if (index >= 0 && index < length) {
                            List<String> result = new ArrayList<String>();
                            String min = rs.getString("min");
                            String max = rs.getString("max");
                            if (!PlatformObjectUtils.isEmpty(min) && !PlatformObjectUtils.isEmpty(max)) {
                                result.add(min);//最小值
                                result.add(max);//最大值
                            }
                            if (!PlatformObjectUtils.isEmpty(searchType2)) {//查询字段值2
                                String min2 = rs.getString("min2");
                                String max2 = rs.getString("max2");
                                if (!PlatformObjectUtils.isEmpty(min2) && !PlatformObjectUtils.isEmpty(max2)) {
                                    result.add(min2);//最小值
                                    result.add(max2);//最大值
                                }
                            }
                            if (!PlatformObjectUtils.isEmpty(searchType3)) {//查询字段值3
                                String min3 = rs.getString("min3");
                                String max3 = rs.getString("max3");
                                if (!PlatformObjectUtils.isEmpty(min3) && !PlatformObjectUtils.isEmpty(max3)) {
                                    result.add(min3);//最小值
                                    result.add(max3);//最大值
                                }
                            }
                            if (!PlatformObjectUtils.isEmpty(searchType4)) {//查询字段值4
                                String min4 = rs.getString("min4");
                                String max4 = rs.getString("max4");
                                if (!PlatformObjectUtils.isEmpty(min4) && !PlatformObjectUtils.isEmpty(max4)) {
                                    result.add(min4);//最小值
                                    result.add(max4);//最大值
                                }
                            }
                            //设置查询结果
                            resultList.set(index, result);
                        }
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据查询类型、taskId、震级、角度、序号、经度、纬度，查询评估结果（选择角度：1条数据）
    @Override
    public List<List<String>> queryEvaluateResultTotalDetailsByAngle(String type, String taskId, String level, String angle, String num, String longitude, String latitude) {
        List<List<String>> resultList = new ArrayList<List<String>>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(type) && !PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(level) && !PlatformObjectUtils.isEmpty(angle)
                    && !PlatformObjectUtils.isEmpty(num) && !PlatformObjectUtils.isEmpty(longitude) && !PlatformObjectUtils.isEmpty(latitude)) {
                conn = getConnection();
                String searchType = "";//查询字段值
                String searchType2 = "";//查询字段值2
                String searchType3 = "";//查询字段值3
                String searchType4 = "";//查询字段值4
                if (type.equals("人员伤亡")) {
                    searchType = "death_toll";//死亡人数（人）
                    searchType2 = "injured_num";//受伤人数（人）--查询字段值2
                } else if (type.equals("经济损失")) {
                    searchType = "disaster_loss";
                } else if (type.equals("需紧急安置人数")) {
                    searchType = "resettled_num";
                } else if (type.equals("需救援队伍")) {
                    searchType = "rescue_force";//需救援队伍（人）
                    searchType2 = "rescue_force_zy";//专业救援力量（人）--查询字段值2
                    searchType3 = "rescue_force_mj";//民间救援力量（人）--查询字段值3
                    searchType4 = "rescue_force_qt";//社会其他救援力量（人）--查询字段值4
                } else if (type.equals("需医务人员")) {
                    searchType = "medical_matters";//需医务人员（人）
                    searchType2 = "medical_num";//医生（人）--查询字段值2
                    searchType3 = "nurse_num";//护士（人）--查询字段值3
                    searchType4 = "psychologist";//心理医生（人）--查询字段值4
                } else if (type.equals("需帐篷数")) {//需救援物资
                    searchType = "tent_num";
                } else if (type.equals("需担架")) {//需救援物资
                    searchType = "stretcher_num";
                } else if (type.equals("需棉被")) {//需救援物资
                    searchType = "quilts_num";
                } else if (type.equals("需食品")) {//需救援物资
                    searchType = "foods_num";
                } else if (type.equals("需饮水")) {//需救援物资
                    searchType = "water_num";
                } else if (type.equals("需临时厕所")) {//需救援物资
                    searchType = "bathroom_num";
                } else if (type.equals("需临时浴室")) {//需救援物资
                    searchType = "showers_num";
                } else if (type.equals("需医疗物资")) {
                    searchType = "sickroom_num";//需病房（平方米）
                    searchType2 = "sickbed_num";//需病床（张）--查询字段值2
                    searchType3 = "plasma_num";//需血浆（升）--查询字段值3
                }

                //查询
                if (!PlatformObjectUtils.isEmpty(searchType)) {
                    String tempSql = "select " + searchType;
                    if (!PlatformObjectUtils.isEmpty(searchType2)) {//查询字段值2
                        tempSql += "," + searchType2;
                    }
                    if (!PlatformObjectUtils.isEmpty(searchType3)) {//查询字段值3
                        tempSql += "," + searchType3;
                    }
                    if (!PlatformObjectUtils.isEmpty(searchType4)) {//查询字段值4
                        tempSql += "," + searchType4;
                    }
                    tempSql += " from ypg_result_total_details ";
                    StringBuilder sql = new StringBuilder(tempSql);
                    String whereSql = "where del_flag='0' and task_id='" + taskId + "'" +
                            " and sort='" + num + "' and angle='" + angle + "' and magnitude='" + level + "'" +
                            " and longitude='" + longitude + "' and latitude='" + latitude + "' ";
                    sql.append(whereSql);
                    String groupSql = "group by " + searchType;
                    if (!PlatformObjectUtils.isEmpty(searchType2)) {//查询字段值2
                        groupSql += "," + searchType2;
                    }
                    if (!PlatformObjectUtils.isEmpty(searchType3)) {//查询字段值3
                        groupSql += "," + searchType3;
                    }
                    if (!PlatformObjectUtils.isEmpty(searchType4)) {//查询字段值4
                        groupSql += "," + searchType4;
                    }
                    sql.append(groupSql);
                    String limitSql = " limit 1 ";
                    sql.append(limitSql);
                    ps = conn.prepareStatement(sql.toString());
                    rs = ps.executeQuery();
                    while (rs.next()) {
                        List<String> result = new ArrayList<String>();
                        String searchTypeValue = rs.getString(searchType);
                        if (!PlatformObjectUtils.isEmpty(searchTypeValue)) {
                            result.add(searchTypeValue);//字段值
                        }
                        if (!PlatformObjectUtils.isEmpty(searchType2)) {//查询字段值2
                            String searchTypeValue2 = rs.getString(searchType2);
                            if (!PlatformObjectUtils.isEmpty(searchTypeValue2)) {
                                result.add(searchTypeValue2);//字段值2
                            }
                        }
                        if (!PlatformObjectUtils.isEmpty(searchType3)) {//查询字段值3
                            String searchTypeValue3 = rs.getString(searchType3);
                            if (!PlatformObjectUtils.isEmpty(searchTypeValue3)) {
                                result.add(searchTypeValue3);//字段值3
                            }
                        }
                        if (!PlatformObjectUtils.isEmpty(searchType4)) {//查询字段值4
                            String searchTypeValue4 = rs.getString(searchType4);
                            if (!PlatformObjectUtils.isEmpty(searchTypeValue4)) {
                                result.add(searchTypeValue4);//字段值4
                            }
                        }
                        //设置查询结果
                        resultList.add(result);
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据taskId、震级、角度、序号、经度、纬度，按烈度从小到大排序查询地震影响场
    @Override
    public List<List<String>> queryInfluencefliedEllipse(String taskId, String level, String angle, String num, String longitude, String latitude) {
        List<List<String>> resultList = new ArrayList<List<String>>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(taskId) && !PlatformObjectUtils.isEmpty(level) && !PlatformObjectUtils.isEmpty(angle)
                    && !PlatformObjectUtils.isEmpty(num) && !PlatformObjectUtils.isEmpty(longitude) && !PlatformObjectUtils.isEmpty(latitude)) {
                conn = getConnection();
                StringBuilder sql = new StringBuilder("SELECT dz_intensity,long_x,short_y,ST_AsText(geom) geomText FROM setting_seismic_influenceflied ");
                /*String whereSql = "where task_id='"+taskId+"' and source_earthquake_id in (" +
                        "select b.id FROM setting_seismic_details b " +
                        "where b.ss_id in (select c.ss_id from setting_seismic_point c " +
                        "where c.task_id='"+taskId+"') and b.earthquake_level='"+level+"' and b.angle='"+angle+"' " +
                        "and b.fault_num='"+num+"' and b.longitude='"+longitude+"' and latitude='"+latitude+"') ";*/
                //导入影响场及生成影响场查询
                String whereSql = "where task_id='" + taskId + "' and (data_source='3' or source_earthquake_id in (" +
                        "select b.id FROM setting_seismic_details b " +
                        "where b.ss_id in (select c.ss_id from setting_seismic_point c " +
                        "where c.task_id='" + taskId + "') and b.earthquake_level='" + level + "' and b.angle='" + angle + "' " +
                        "and b.fault_num='" + num + "' and b.longitude='" + longitude + "' and latitude='" + latitude + "')) ";
                sql.append(whereSql);
                String orderSql = "order by cast(dz_intensity as int) asc";
                sql.append(orderSql);
                ps = conn.prepareStatement(sql.toString());
                rs = ps.executeQuery();
                while (rs.next()) {
                    List<String> result = new ArrayList<String>();
                    String dzIntensity = rs.getString("dz_intensity");
                    result.add(dzIntensity);//烈度
                    String longX = rs.getString("long_x");
                    result.add(longX);//长轴
                    String shortY = rs.getString("short_y");
                    result.add(shortY);//短轴
                    String geomText = rs.getString("geomText");
                    result.add(geomText);//空间数据
                    resultList.add(result);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return resultList;
    }

    //根据起点、终点的经纬度查询与正东方向的夹角[0-180]
    @Override
    public String queryPointAzimuthAngleEast(String startLon, String startLat, String endLon, String endLat) {
        //根据起点、终点的经纬度查询与正北方向的夹角
        String angle = queryPointAzimuthAngle(startLon, startLat, endLon, endLat);
        if (!PlatformObjectUtils.isEmpty(angle)) {
            double angleNumber = Double.parseDouble(angle);
            if (angleNumber >= 0 && angleNumber <= 90) {
                angleNumber = 90 - angleNumber;
            } else if (angleNumber > 90 && angleNumber < 180) {
                angleNumber = 90 + angleNumber;
            } else if (angleNumber >= 180 && angleNumber <= 270) {
                angleNumber = angleNumber - 90;
            } else if (angleNumber > 270 && angleNumber < 360) {
                angleNumber = 360 - angleNumber + 90;
            }
            angle = String.valueOf(angleNumber);
        }

        return angle;
    }

    //根据起点、终点的经纬度查询与正北方向的夹角[0,360)
    @Override
    public String queryPointAzimuthAngle(String startLon, String startLat, String endLon, String endLat) {
        String angle = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(startLon) && !PlatformObjectUtils.isEmpty(startLat)
                    && !PlatformObjectUtils.isEmpty(endLon) && !PlatformObjectUtils.isEmpty(endLat)) {
                conn = getConnection();
                String sql = "SELECT degrees(ST_Azimuth(ST_GeomFromText('Point(" + startLon + " " + startLat + ")',4490)," +
                        "ST_GeomFromText('Point(" + endLon + " " + endLat + ")',4490))) as angle";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    angle = rs.getString("angle");//与正北方向的夹角
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return angle;
    }

    //查询P1P2P3夹角,如果angle值大于180则夹角为360-angle，否则夹角为angle，夹角范围为[0,180]
    @Override
    public String queryP1P2P3Angle(String P1LonLat, String P2LonLat, String P3LonLat) {
        String angle = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(P1LonLat) && !PlatformObjectUtils.isEmpty(P2LonLat)
                    && !PlatformObjectUtils.isEmpty(P3LonLat)) {
                conn = getConnection();
                String sql = "SELECT degrees(ST_Angle(st_geometryfromtext('Point(" + P1LonLat + ")',4490)," +
                        "st_geometryfromtext('Point(" + P2LonLat + ")',4490)," +
                        "st_geometryfromtext('Point(" + P3LonLat + ")',4490)))";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String degrees = rs.getString("degrees");//P1P2P3夹角(顺时针方向夹角)
                    if (!PlatformObjectUtils.isEmpty(degrees)) {
                        double angleNumber = Double.parseDouble(degrees);
                        if (angleNumber >= 0 && angleNumber <= 180) {
                            angle = String.valueOf(angleNumber);
                        } else if (angleNumber > 180 && angleNumber < 360) {
                            angleNumber = 360 - angleNumber;
                            angle = String.valueOf(angleNumber);
                        }
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return angle;
    }

    //查询一个经纬度点附近最近的断层线空间数据
    @Override
    public String getClosestFaultageGeomByLonLat(String lon, String lat) {
        String geom = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                String sql = "select st_astext(geom) as geom from data_faultage " +
                        "ORDER BY st_distance(geom,st_geometryfromtext('POINT(" + lon + " " + lat + ")',4490)) LIMIT 1";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    geom = rs.getString("geom");//断层线空间数据
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return geom;
    }

    //查询点到断层线的最短线段
    @Override
    public String getShortestLineFaultageGeomByLonLat(String lon, String lat) {
        String geom = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                String sql = "select st_astext(ST_ShortestLine(geom," +
                        "st_geometryfromtext('POINT(" + lon + " " + lat + ")',4490))) as geom from data_faultage " +
                        "ORDER BY st_distance(geom,st_geometryfromtext('POINT(" + lon + " " + lat + ")',4490)) LIMIT 1";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    geom = rs.getString("geom");//点到断层线的最短线段的空间数据
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return geom;
    }

    //查询点到断层线上的最短距离的点
    @Override
    public String getClosestPointFaultageGeomByLonLat(String lon, String lat) {
        String geom = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                String sql = "SELECT ST_AsText(ST_ClosestPoint(geom," +
                        "st_geometryfromtext('POINT(" + lon + " " + lat + ")',4490))) as geom from data_faultage " +
                        "ORDER BY st_distance(geom,st_geometryfromtext('POINT(" + lon + " " + lat + ")',4490)) LIMIT 1";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    geom = rs.getString("geom");//查询点到断层线上的最短距离的点
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return geom;
    }

    //查询点到P1P2线段的距离
    @Override
    public String getDistanceByLonLatP1P2(String lon, String lat, String P1LonLat, String P2LonLat) {
        String distance = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                conn = getConnection();
                String sql = "select st_distance(st_geometryfromtext('LINESTRING(" + P1LonLat + "," + P2LonLat + ")',4490)," +
                        "st_geometryfromtext('POINT(" + lon + " " + lat + ")',4490))";

                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    distance = rs.getString("st_distance");//查询点到P1P2线段的距离
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return distance;
    }

    //根据经纬度查询最近断层切线角度（与正东方向的夹角，[0,180]）
    @Override
    public String getClosestFaultageAngleByLonLat(String lon, String lat) {
        String angle = null;
        try {
            String pointGeom = "st_geometryfromtext('POINT("+lon+" "+lat+")',4490)";
            if (!PlatformObjectUtils.isEmpty(lon) && !PlatformObjectUtils.isEmpty(lat)) {
                String sql = "select ST_LineLocatePoint(line_geom, closest_point) FROM " +
                        "(SELECT (ST_Dump(geom)).geom AS line_geom FROM data_faultage where fau_isdelete='0' " +
                        "ORDER BY ST_Distance(geom, "+pointGeom+") ASC LIMIT 1) as nearest_line," +
                        "ST_ClosestPoint(line_geom, "+pointGeom+") AS closest_point";
                //最近断层线上的最近点在线段的比例
                double temp = jdbcTemplate.queryForObject(sql, Double.class);
                if(temp>=0 && temp<=1){
                    double temp1 = 0;//最近断层线上的最近点的附近点在线段的比例
                    if(temp<1){
                        if(temp>0){//(0,1)
                            temp1 = temp + 0.01;
                            if(temp1>1){
                                temp1 = 1;
                            }
                        }else{//0
                            temp1 = temp + 0.01;
                        }
                    }else{//1
                        temp1 = temp - 0.01;
                    }
                    //最近断层线上的最近点
                    String sql1 = "select ST_astext(ST_LineInterpolatePoint(line_geom,"+temp+")) as point1 FROM " +
                            "(SELECT (ST_Dump(geom)).geom AS line_geom FROM data_faultage where fau_isdelete='0' " +
                            "ORDER BY ST_Distance(geom, "+pointGeom+") ASC LIMIT 1) as nearest_line," +
                            "ST_ClosestPoint(line_geom, "+pointGeom+") AS closest_point";
                    String point1 = jdbcTemplate.queryForObject(sql1, String.class);
                    //最近断层线上的最近点的附近点
                    String sql2 = "select ST_astext(ST_LineInterpolatePoint(line_geom,"+temp1+")) as point2 FROM " +
                            "(SELECT (ST_Dump(geom)).geom AS line_geom FROM data_faultage where fau_isdelete='0' " +
                            "ORDER BY ST_Distance(geom, "+pointGeom+") ASC LIMIT 1) as nearest_line," +
                            "ST_ClosestPoint(line_geom, "+pointGeom+") AS closest_point";
                    String point2 = jdbcTemplate.queryForObject(sql2, String.class);
                    if (!PlatformObjectUtils.isEmpty(point1) && !PlatformObjectUtils.isEmpty(point2)
                            && point1.contains("POINT(") && point2.contains("POINT(")) {
                        String temp1LonLat = point1.replace("POINT(","");
                        temp1LonLat = temp1LonLat.replace(")","");
                        String[] temp1LonLatArr = temp1LonLat.split(" ");
                        String temp2LonLat = point2.replace("POINT(","");
                        temp2LonLat = temp2LonLat.replace(")","");
                        String[] temp2LonLatArr = temp2LonLat.split(" ");
                        if(temp1LonLatArr.length==2 && temp2LonLatArr.length==2){
                            double temp1Lon = Double.parseDouble(temp1LonLatArr[0]);
                            double temp1Lat = Double.parseDouble(temp1LonLatArr[1]);
                            double temp2Lon = Double.parseDouble(temp2LonLatArr[0]);
                            double temp2Lat = Double.parseDouble(temp2LonLatArr[1]);
                            //取纬度小的为P2
                            if (temp1Lat > temp2Lat) {
                                String P1LonLat = temp1LonLat;
                                String P2LonLat = temp2LonLat;
                                //P3为P2同纬度，经度增加1度的点
                                String P3LonLat = (temp2Lon + 1) + " " + temp2Lat;
                                //查询P1P2P3夹角,如果angle值大于180则夹角为360-angle，否则夹角为angle，夹角范围为[0,180]
                                angle = queryP1P2P3Angle(P1LonLat, P2LonLat, P3LonLat);
                            } else {
                                String P1LonLat = temp2LonLat;
                                String P2LonLat = temp1LonLat;
                                //P3为P2同纬度，经度增加1度的点
                                String P3LonLat = (temp1Lon + 1) + " " + temp1Lat;
                                //查询P1P2P3夹角,如果angle值大于180则夹角为360-angle，否则夹角为angle，夹角范围为[0,180]
                                angle = queryP1P2P3Angle(P1LonLat, P2LonLat, P3LonLat);
                            }
                        }
                    }
                }

                /*//查询一个经纬度点附近最近的断层线空间数据
                String geomText = getClosestFaultageGeomByLonLat(lon, lat);
                if (!PlatformObjectUtils.isEmpty(geomText)) {
                    String tempString = null;
                    if (geomText.indexOf("MULTILINESTRING((") != -1) {
                        tempString = geomText.split("MULTILINESTRING\\(\\(")[1].split("\\)\\)")[0];
                    } else if (geomText.indexOf("LINESTRING(") != -1) {
                        tempString = geomText.split("LINESTRING\\(")[1].split("\\)")[0];
                    }
                    if (!PlatformObjectUtils.isEmpty(tempString)) {
                        boolean bool = false;
                        int mIndex = -1;
                        int index = -1;
                        double distanceTemp = -1;
                        String[] tempStringArr = tempString.split("\\),\\(");
                        for (int m = 0; m < tempStringArr.length; m++) {
                            String tempStr = tempStringArr[m];
                            if (!PlatformObjectUtils.isEmpty(tempStr)) {
                                String[] tempStrArr = tempStr.split(",");
                                if (tempStrArr != null && tempStrArr.length >= 2) {
                                    for (int i = 0; i < tempStrArr.length; i++) {
                                        if (i < (tempStrArr.length - 1)) {
                                            String P1LonLat = tempStrArr[i];
                                            String P2LonLat = tempStrArr[i + 1];
                                            //查询点到P1P2线段的距离
                                            String distanceStr = getDistanceByLonLatP1P2(lon, lat, P1LonLat, P2LonLat);
                                            if (!PlatformObjectUtils.isEmpty(distanceStr)) {
                                                double distance = Double.parseDouble(distanceStr);
                                                if (distance < distanceTemp || distanceTemp < 0) {
                                                    distanceTemp = distance;
                                                    mIndex = m;
                                                    index = i;//获取点到断层线段的最短距离的序号
                                                }
                                                if (distanceTemp == 0) {
                                                    bool = true;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    if (bool) {
                                        break;
                                    }
                                }
                            }
                        }
                        if (mIndex >= 0 && index >= 0) {
                            String tempStr = tempStringArr[mIndex];
                            String[] tempStrArr = tempStr.split(",");
                            String temp1LonLat = tempStrArr[index];
                            String[] temp1LonLatArr = temp1LonLat.split(" ");
                            double temp1Lon = Double.parseDouble(temp1LonLatArr[0]);
                            double temp1Lat = Double.parseDouble(temp1LonLatArr[1]);
                            String temp2LonLat = tempStrArr[index + 1];
                            String[] temp2LonLatArr = temp2LonLat.split(" ");
                            double temp2Lon = Double.parseDouble(temp2LonLatArr[0]);
                            double temp2Lat = Double.parseDouble(temp2LonLatArr[1]);
                            //取纬度小的为P2
                            if (temp1Lat > temp2Lat) {
                                String P1LonLat = temp1LonLat;
                                String P2LonLat = temp2LonLat;
                                //P3为P2同纬度，经度增加1度的点
                                String P3LonLat = (temp2Lon + 1) + " " + temp2Lat;
                                //查询P1P2P3夹角,如果angle值大于180则夹角为360-angle，否则夹角为angle，夹角范围为[0,180]
                                angle = queryP1P2P3Angle(P1LonLat, P2LonLat, P3LonLat);
                            } else {
                                String P1LonLat = temp2LonLat;
                                String P2LonLat = temp1LonLat;
                                //P3为P2同纬度，经度增加1度的点
                                String P3LonLat = (temp1Lon + 1) + " " + temp1Lat;
                                //查询P1P2P3夹角,如果angle值大于180则夹角为360-angle，否则夹角为angle，夹角范围为[0,180]
                                angle = queryP1P2P3Angle(P1LonLat, P2LonLat, P3LonLat);
                            }
                        }
                    }
                }*/
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return angle;
    }

    //根据全部经纬度字符串批量查询最近断层切线角度列表（与正东方向的夹角，[0,180]）
    @Override
    public List<String> getClosestFaultageAngleListByLonLatsString(String lonlatsString) {
        List<String> angleList = new ArrayList<String>();
        try {
            if (!PlatformObjectUtils.isEmpty(lonlatsString)) {
                boolean bool = true;
                String[] lonlatStrArr = lonlatsString.split(";");
                if (lonlatStrArr != null && lonlatStrArr.length > 0) {
                    for (int i = 0; i < lonlatStrArr.length; i++) {
                        String lonlatStr = lonlatStrArr[i];
                        if (!PlatformObjectUtils.isEmpty(lonlatStr)) {
                            String[] lonlat = lonlatStr.split(",");
                            if (lonlat != null && lonlat.length == 2) {
                                String angle = getClosestFaultageAngleByLonLat(lonlat[0], lonlat[1]);
                                if (!PlatformObjectUtils.isEmpty(angle)) {
                                    angleList.add(angle);
                                } else {
                                    bool = false;
                                }
                            }
                        } else {
                            bool = false;
                        }
                    }
                } else {
                    bool = false;
                }
                if (bool == false) {
                    angleList.clear();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return angleList;
    }

    @Override
    public String getGeomByDivision(String province, String city, String county) {
        String geom = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            if (PlatformObjectUtils.isNotEmpty(province)) {
                String sql = "select";
                if (PlatformObjectUtils.isEmpty(city)) {
                    sql = sql + " ST_AsText(t1.geom) geomText FROM district_boundary_province t1 where t1.name=" + province;
                } else {
                    if (PlatformObjectUtils.isEmpty(county)) {
                        sql = sql + " ST_AsText(t2.geom) geomText FROM district_boundary_province t1" +
                                " right join district_boundary_city t2 on t1.code=subString(t2.code,0,2) || '0000'" +
                                " where t1.name=" + province + " and t2.name=" + city;
                    } else {
                        sql = sql + " ST_AsText(t3.geom) geomText FROM district_boundary_province t1" +
                                " right join district_boundary_city t2 on t1.code=subString(t2.code,0,2) || '0000'" +
                                " right join district_boundary_county t3 on t2.code=subString(t3.code,0,4) || '00'" +
                                " where t1.name=" + province + " and t2.name=" + city + " and t3.name=" + county;
                    }
                }
                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    geom = rs.getString("geomText");//查询点到P1P2线段的距离
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (ps != null) {
                    // 关闭连接
                    ps.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        return geom;
    }

    //椭圆--地震影响场
    /**
     * 定义地球半径（米）
     */
    //private final double R_EARTH = 6371000;
    private final double R_EARTH = 6378137;

    /**
     * 定义地球赤道周长（米）
     */
    private final double P_EARTH = 2 * Math.PI * R_EARTH;

    /**
     * 将Y轴的长度（米）转换成纬度
     *
     * @param length
     * @return
     */
    public double parseYLengthToDegree(double length) {
        //将length长度转换为度数
        double yDegree = length / P_EARTH * 360;
        return yDegree;
    }

    /**
     * 根据所在纬度，将X轴的长度（米）转换成经度
     * （因为不同纬度下，1°经度代表的长度不同）
     *
     * @param y      所在纬度
     * @param length 线段长度
     * @return
     */
    public double parseXLengthToDegree(double y, double length) {
        //将角度（纬度）转换为弧度
        double latRadian = Math.toRadians(y);
        //计算当前纬度地球周长
        double latPEarth = P_EARTH * Math.cos(latRadian);
        //将length长度转换为度数
        double xDegree = length / latPEarth * 360;
        return xDegree;
    }

    /**
     * 根据圆形中心点经纬度、半径生成圆形（类圆形，32边多边形）
     *
     * @param x      中心点经度
     * @param y      中心点纬度
     * @param radius 半径（米）
     * @return
     */
    public Polygon createCircle(double x, double y, final double radius) {
        //将半径转换为度数
        double radiusDegree = parseYLengthToDegree(radius);
        //生成工厂类
        GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
        //设置生成的类圆形边数
        shapeFactory.setNumPoints(32);
        //设置圆形中心点经纬度
        shapeFactory.setCentre(new Coordinate(x, y));
        //设置圆形直径
        shapeFactory.setSize(radiusDegree * 2);
        //使用工厂类生成圆形
        Polygon circle = shapeFactory.createCircle();
        return circle;
    }

    /**
     * 根据中心点经纬度、长轴、短轴、角度生成椭圆
     *
     * @param x
     * @param y
     * @param macroaxis
     * @param brachyaxis
     * @param direction
     * @return
     */
    public Polygon createEllipse(double x, double y, double macroaxis, double brachyaxis, double direction) {
        //将长短轴转换为度数
        double macroaxisDegree = parseXLengthToDegree(y, macroaxis);
        double brachyaxisDegree = parseYLengthToDegree(brachyaxis);
        //将夹角转换为弧度
        double radians = Math.toRadians(direction);
        //生成工厂类
        GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
        //设置中心点
        shapeFactory.setCentre(new Coordinate(x, y));
        //设置长轴长度
        shapeFactory.setWidth(macroaxisDegree);
        //设置短轴长度
        shapeFactory.setHeight(brachyaxisDegree);
        //设置长轴和X轴夹角
        shapeFactory.setRotation(radians);
        //生成椭圆对象
        Polygon ellipse = shapeFactory.createEllipse();
        return ellipse;
    }

    /**
     * 根据中心点经纬度、半径、起止角度生成扇形
     *
     * @param x         经度
     * @param y         纬度
     * @param radius    半径（米）
     * @param bAngle    起始角度
     * @param eAngle    终止角度
     * @param pointsNum 点数
     * @return
     */
    public Polygon createSector(double x, double y, double radius, double bAngle, double eAngle, int pointsNum) {
        //将半径转换为度数
        double radiusDegree = parseYLengthToDegree(radius);
        //将起始角度转换为弧度
        double bAngleRadian = Math.toRadians(bAngle);
        //将终止角度-起始角度计算扇形夹角
        double angleRadian = Math.toRadians((eAngle - bAngle + 360) % 360);
        //生成工厂类
        GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
        //设置点数
        shapeFactory.setNumPoints(pointsNum);
        //设置中心点经纬度
        shapeFactory.setCentre(new Coordinate(x, y));
        //设置直径
        shapeFactory.setSize(radiusDegree * 2);
        //传入起始角度和扇形夹角，生成扇形
        Polygon sector = shapeFactory.createArcPolygon(bAngleRadian, angleRadian);
        return sector;
    }
}
